package com.haitaoit.chengquan.module.center.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.haitaoit.chengquan.R;
import com.haitaoit.chengquan.base.BackCall;
import com.haitaoit.chengquan.module.center_service.model.ServiceEvaluateModel;
import com.haitaoit.chengquan.module.home.adapter.forum.ForumCenterImgAdapter;
import com.haitaoit.chengquan.module.home.adapter.forum.ForumCenterImgAdapterTwo;
import com.haitaoit.chengquan.view.CircleImageView;
import com.haitaoit.chengquan.view.MyGridView;
import com.haitaoit.chengquan.view.QRatingBar;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by Administrator on 2016/10/11.
 */
public class MyEvaluateAdapter extends BaseAdapter {
    private Context context;
    private BackCall backCall;
    private List<ServiceEvaluateModel> list;
    private String type;
    private ForumCenterImgAdapterTwo mAdapter;
    private ForumCenterImgAdapterTwo mAdapter1;

    public void setType(String type) {
        this.type = type;
    }

    public void setBackCall(BackCall backCall) {
        this.backCall = backCall;
    }

    public MyEvaluateAdapter(Context context) {
        this.context = context;
    }

    public List<ServiceEvaluateModel> getList() {
        return list;
    }

    public void setList(List<ServiceEvaluateModel> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.my_evaluate_item, null);
            holder = new ViewHolder();
            ViewUtils.inject(holder, convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (type.equals("send")) {
            holder.eva_send_LL.setVisibility(View.VISIBLE);
            holder.eva_forme_LL.setVisibility(View.GONE);
            holder.eva_store_LL.setVisibility(View.GONE);
            holder.forum_gridview.setVisibility(View.GONE);

            ImageLoader.getInstance().displayImage(list.get(position).getHead_portrait(), holder.center_img);
            holder.eva_name.setText(list.get(position).getName());
            holder.credit_rating.setText("信誉评分：" + list.get(position).getCredit_rating());
            holder.eva_content.setText(list.get(position).getContent());
            holder.addtime2.setText(list.get(position).getAddtime());
            holder.eva_star.setRating(Float.valueOf(list.get(position).getScore()));

            if (list.get(position).getList_img().size() == 0) {
                holder.forum_gridview2.setVisibility(View.GONE);
            } else {
                holder.forum_gridview2.setVisibility(View.VISIBLE);
                mAdapter = new ForumCenterImgAdapterTwo(context);
                mAdapter.setList(list.get(position).getList_img());
                holder.forum_gridview2.setAdapter(mAdapter);



            }
        } else if (type.equals("forme")) {
            holder.eva_send_LL.setVisibility(View.GONE);
            holder.eva_forme_LL.setVisibility(View.VISIBLE);
            holder.eva_store_LL.setVisibility(View.GONE);

            holder.eva_send_LL.setVisibility(View.GONE);
            holder.eva_forme_LL.setVisibility(View.VISIBLE);
            ImageLoader.getInstance().displayImage(list.get(position).getHead_portrait(), holder.center_img2);
            holder.name.setText(list.get(position).getName());
            holder.content.setText(list.get(position).getContent());
            holder.addtime.setText(list.get(position).getAddtime());
            holder.eva_star2.setRating(Float.valueOf(list.get(position).getScore()));
            if (list.get(position).getList_img().size() == 0) {
                holder.forum_gridview.setVisibility(View.GONE);
            } else {
                holder.forum_gridview.setVisibility(View.VISIBLE);
                mAdapter1 = new ForumCenterImgAdapterTwo(context);
                mAdapter1.setList(list.get(position).getList_img());
                holder.forum_gridview.setAdapter(mAdapter1);
            }
        } else if (type.equals("store")) {
            holder.eva_send_LL.setVisibility(View.GONE);
            holder.eva_forme_LL.setVisibility(View.GONE);
            holder.eva_store_LL.setVisibility(View.VISIBLE);
            ImageLoader.getInstance().displayImage(list.get(position).getAccessories_goods_evaluation_img(), holder.store_img);
            holder.store_name.setText(list.get(position).getAccessories_goods_title());
            holder.eva_content2.setText(list.get(position).getContent());
            holder.eva_addtime.setText(list.get(position).getAddtime());
            holder.eva_star3.setRating(Float.valueOf(list.get(position).getScore()));
            if (list.get(position).getList_img().size() == 0) {
                holder.forum_gridview.setVisibility(View.GONE);
            } else {
                holder.forum_gridview.setVisibility(View.VISIBLE);
                ForumCenterImgAdapter adapter = new ForumCenterImgAdapter(context);
                adapter.setList(list.get(position).getList_img());
                holder.forum_gridview.setAdapter(adapter);
            }
        }
        return convertView;
    }

    class ViewHolder {
        @ViewInject(R.id.forum_gridview2)
        MyGridView forum_gridview2;
        @ViewInject(R.id.forum_gridview)
        MyGridView forum_gridview;
        @ViewInject(R.id.eva_send_LL)
        LinearLayout eva_send_LL;
        @ViewInject(R.id.eva_forme_LL)
        LinearLayout eva_forme_LL;
        @ViewInject(R.id.eva_store_LL)
        LinearLayout eva_store_LL;
        @ViewInject(R.id.center_img)
        CircleImageView center_img;
        @ViewInject(R.id.center_img2)
        CircleImageView center_img2;
        @ViewInject(R.id.store_img)
        ImageView store_img;
        @ViewInject(R.id.name)
        TextView name;
        @ViewInject(R.id.content)
        TextView content;
        @ViewInject(R.id.addtime)
        TextView addtime;
        @ViewInject(R.id.eva_star)
        QRatingBar eva_star;
        @ViewInject(R.id.eva_star2)
        QRatingBar eva_star2;
        @ViewInject(R.id.eva_star3)
        QRatingBar eva_star3;
        @ViewInject(R.id.eva_name)
        TextView eva_name;
        @ViewInject(R.id.credit_rating)
        TextView credit_rating;
        @ViewInject(R.id.eva_content)
        TextView eva_content;
        @ViewInject(R.id.addtime2)
        TextView addtime2;
        @ViewInject(R.id.store_name)
        TextView store_name;
        @ViewInject(R.id.eva_content2)
        TextView eva_content2;
        @ViewInject(R.id.eva_addtime)
        TextView eva_addtime;
    }
}
